from binance.client import Client
from itertools import permutations

# 使用你的 API key 和 secret 初始化 Binance 客户端
client = Client(api_key='W1Z5h7RydJ8CNI40azIXOJKVudRLfawy3k8jEdbh0sfU74yHQzVr5a78IU2E2lRV', api_secret='ZMvkc39AOccvuxLnREzFPx7UZY11grocC08qO8R1lSe7L5yGyyZyq4WlwxF0u0gr')


# 获取所有交易对信息
exchange_info = client.get_exchange_info()

# 提取所有交易对
symbols = [s['symbol'] for s in exchange_info['symbols'] if s['status'] == 'TRADING']
print('所有交易对:',symbols)

currencies = set()
for symbol_info in exchange_info['symbols']:
    if symbol_info['status'] == 'TRADING':
        currencies.add(symbol_info['baseAsset'])
        currencies.add(symbol_info['quoteAsset'])

print(sorted(currencies))

print(f"一共有 {len(currencies)} 种货币。")
print(f"一共有 {len(symbols)} 交易对。")

# 找出所有可能的三角套利组合
triangular_arbitrage_paths = []
for a, b, c in permutations(["USDT","BNB","BTC"], 3):
    print(a,b,c)
    print(f"{a}{b}",f"{b}{c}",f"{c}{a}")
    print(f"{b}{a}",f"{a}{c}",f"{c}{b}")
    if (f"{a}{b}" in symbols and f"{b}{c}" in symbols and f"{c}{a}" in symbols):
        triangular_arbitrage_paths.append((f"{a}{b}", f"{b}{c}", f"{c}{a}"))
    if (f"{b}{a}" in symbols and f"{a}{c}" in symbols and f"{c}{b}" in symbols):
        triangular_arbitrage_paths.append((f"{b}{a}", f"{a}{c}", f"{c}{b}"))

# 打印所有找到的三角套利组合
print(f"找到了 {len(triangular_arbitrage_paths)} 组三角套利路径：")
for path in triangular_arbitrage_paths:
    print(" -> ".join(path))
